<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="测评订单状态" prop="status">
        <el-select v-model="queryParams.status">
          <el-option v-for="item in dict.type.evaluation_status" :key="item.value" :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单号" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入订单号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="运单号" prop="intlTrackingNo">
        <el-input v-model="queryParams.intlTrackingNo" placeholder="请输入运单号" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="evaluationList" @selection-change="handleSelectionChange"
              stripe border>
      <el-table-column type="selection" width="40" align="center"/>
      <el-table-column label="店铺名称" align="center" prop="storeName"/>
      <el-table-column label="卖家全称" align="center" prop="sellerSignerFullname"/>
      <el-table-column label="国家" align="center" prop="country" width="50">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_evaluation_country" :value="scope.row.country"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="产品主图" align="center" prop="productImg">
        <template slot-scope="scope">
          <imagePreview :src="scope.row.productImg" width="50px" height="50px"/>
        </template>
      </el-table-column>
      <el-table-column label="SKU" align="center" prop="skuCode"/>
      <el-table-column show-overflow-tooltip label="购买链接" align="center" prop="link"/>
      <el-table-column label="测评数量" align="center" prop="number" width="75"/>
      <el-table-column show-overflow-tooltip label="关键词" align="center" prop="keyWord"/>
      <el-table-column label="测评时间" align="center" prop="evaluationTime" width="160">
        <template slot-scope="scope">
          <span>{{ scope.row.evaluationTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采购总费用" align="center" prop="totalAmount" width="150"></el-table-column>
      <el-table-column label="订单号" align="center" prop="orderId" width="250"></el-table-column>
      <el-table-column label="运单号" align="left" prop="intlTrackingNo" width="250"></el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
  </div>
</template>

<script>
import {queryEvaluationOrder} from "@/api/order/orderApi";

export default {
  dicts: ['evaluation_status', 'sys_evaluation_country'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      evaluationList: [],//测评订单列表
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        skuCode: undefined,
        orderId: undefined,
        intlTrackingNo: undefined,
        status: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询在线商品测评列表 */
    getList() {
      this.loading = true;
      queryEvaluationOrder(this.queryParams).then(response => {
        this.evaluationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const ids = this.ids.join(',');
      this.download('gather/sellerStoreProductEvaluation/export', {
        ids
      }, `sellerStoreProductEvaluation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
